home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / Snippets / Toolbox / FreqForEverChange / FreqForEverChange.c next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  8.9 KB  |  382 lines  |  [TEXT/MPS ]

  1. /*______________________________________________________*/
  2. /*                            C Shell                        */
  3. /*                          by                          */
  4. /*                  RICHARD P. COLLYER                  */
  5. /*                       09/02/87                       */
  6. /*______________________________________________________*/
  7.  
  8. #include    <CType.h>
  9. #include    <Quickdraw.h>
  10. #include    <Windows.h>
  11. #include    <OSUtils.h>
  12. #include    <Controls.h>
  13. #include    <desk.h>
  14. #include    <dialogs.h>
  15. #include    <Events.h>
  16. #include    <Memory.h>
  17. #include    <Menus.h>
  18. #include    <Notification.h>
  19. #include    <OSEvents.h>
  20. #include    <Packages.h>
  21. #include    <Palette.h>
  22. #include    <Printing.h>
  23. #include    <Files.h>
  24. #include    <Resources.h>
  25. #include    <SANE.h>
  26. #include    <SegLoad.h>
  27. #include    <Sound.h>
  28. #include    <SoundInput.h>
  29. #include    <Slots.h>
  30. #include    <ToolUtils.h>
  31. #include    <StdIO.h>
  32. #include    <math.h>
  33. #include    <StandardFile.h>
  34.  
  35. extern _DataInit();
  36.  
  37. #define    TRUE            0xFF
  38. #define    FALSE            0
  39. #define    VERSION            1
  40. #define    SR_BIT            0
  41.  
  42. #define    appleID            128            
  43. #define    appleMenu        0
  44. #define    aboutMeCommand    1
  45.  
  46. #define    fileID            129
  47. #define    startCommand    1
  48. #define    printCommand    3
  49. #define    quitCommand     5
  50.  
  51. #define    editID            130
  52.  
  53. #define    aboutMeDLOG        128
  54. #define    okButton        1
  55. #define    authorItem        2
  56. #define    languageItem    3
  57.  
  58. long                Tick, WhereBoard;
  59. int                    yieldTime, err, numcolor, offLeft, offTop, offRight, offBottom;
  60. Rect                screenRect, BaseRect, TotalRect, minRect;
  61. WindowPtr            whichWindow, myWindow;
  62. CTabHandle            mycolors;
  63. PaletteHandle        srcPalette;
  64. MenuHandle            mymenu1, mymenu2, mymenu0;
  65. EventRecord         myEvent;
  66. Boolean                DoneFlag, Color, CPU20, FPU, Sys6, Memboard;
  67. GDHandle            theGDevice;
  68. SysEnvRec            theWorld;
  69. OSErr                OSys;
  70. SpBlockPtr            mySpBlockPtr;
  71. SpBlock                mySpBlock;
  72.     
  73. /*______________________________________________________*/
  74. /*                What ever You want                    */
  75. /*______________________________________________________*/
  76. void start()
  77. {
  78.     Handle            SoundData;
  79.     SndChannelPtr    chan;
  80.     OSErr            err;
  81.     SndCommand        mycmd;
  82.     KeyMap            myKeys;
  83.     
  84.     SoundData = GetResource ('snd ', 100);
  85.     if (ResError() != noErr || SoundData == nil)
  86.         Debugger();
  87.     HLock (SoundData);
  88.             
  89.     mycmd.cmd = soundCmd;
  90.     mycmd.param1 = 0;
  91.     mycmd.param2 = (long) *SoundData;
  92.     
  93.     chan = nil;
  94.     err = SndNewChannel (&chan, sampledSynth, 0, nil);
  95.     if (err != noErr)
  96.         Debugger();
  97.     
  98.     err = SndDoImmediate (chan, &mycmd);
  99.     if (err != noErr)
  100.         Debugger();
  101.  
  102.     mycmd.cmd = freqCmd;
  103.     mycmd.param1 = 0;
  104.     mycmd.param2 = 60;
  105.     
  106.     err = SndDoCommand (chan, &mycmd, FALSE);
  107.     if (err != noErr)
  108.         Debugger();
  109.  
  110.     do {
  111.         GetKeys (myKeys);
  112.         if (((myKeys[3] >> 6) & 1) != FALSE) {
  113.             mycmd.cmd = freqCmd;
  114.             mycmd.param1 = 0;
  115.             mycmd.param2 += 1;
  116.     
  117.             err = SndDoImmediate (chan, &mycmd);
  118.             if (err != noErr)
  119.                 Debugger();
  120.             }
  121.             
  122.         if (((myKeys[3] >> 5) & 1) != FALSE) {
  123.             mycmd.cmd = freqCmd;
  124.             mycmd.param1 = 0;
  125.             mycmd.param2 -= 1;
  126.     
  127.             err = SndDoImmediate (chan, &mycmd);
  128.             if (err != noErr)
  129.                 Debugger();
  130.             }
  131.             
  132.         } while (((myKeys[0] >> 20) & 1) == FALSE);
  133.     
  134.     mycmd.cmd = quietCmd;
  135.     mycmd.param1 = 0;
  136.     mycmd.param2 = 0;
  137.     
  138.     err = SndDoImmediate (chan, &mycmd);
  139.     if (err != noErr)
  140.         Debugger();
  141.  
  142.     err = SndDisposeChannel (chan,FALSE);
  143.     if (err != noErr)
  144.         Debugger();
  145.         
  146.     HUnlock (SoundData);
  147.     return;
  148. }
  149.  
  150. /*______________________________________________________*/
  151. /*                 About Prog Dialog                    */
  152. /*______________________________________________________*/
  153. void showAboutMeDialog()
  154. {
  155.     GrafPtr     savePort;
  156.     DialogPtr    theDialog;
  157.     short        itemHit;
  158.  
  159.     GetPort(&savePort);
  160.     theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
  161.     SetPort(theDialog);
  162.  
  163.     do {
  164.         ModalDialog(nil, &itemHit);
  165.     } while (itemHit != okButton);
  166.  
  167.     CloseDialog(theDialog);
  168.  
  169.     SetPort(savePort);
  170.     return;
  171. }
  172.  
  173. /*______________________________________________________*/
  174. /*                 Do Menu Function                     */
  175. /*______________________________________________________*/
  176. void doCommand(mResult)
  177.     long    mResult;
  178. {
  179.     int                     theMenu, theItem;
  180.     char                    daName[256];
  181.     GrafPtr                 savePort;
  182.  
  183.     theItem = LoWord(mResult);
  184.     theMenu = HiWord(mResult);
  185.     
  186.     switch (theMenu) {
  187. /*______________________________________________________*/
  188. /*                    Do Apple Menu                     */
  189. /*______________________________________________________*/
  190.         case appleID:
  191.             if (theItem == aboutMeCommand)
  192.                 showAboutMeDialog();
  193.             else {
  194.                 GetItem(mymenu0, theItem, daName);
  195.                 GetPort(&savePort);
  196.                 (void) OpenDeskAcc(daName);
  197.                 SetPort(savePort);
  198.             }
  199.             break;
  200. /*______________________________________________________*/
  201. /*                     Do File Menu                     */
  202. /*______________________________________________________*/
  203.         case fileID:
  204.             switch (theItem) {
  205.                 case startCommand:
  206.                     start();
  207.                     break;
  208.                 case printCommand:
  209.                     break;
  210.                 case quitCommand:
  211.                     DoneFlag = TRUE;
  212.                     break;
  213.                 default:
  214.                     break;
  215.                 }
  216.             break;
  217. /*______________________________________________________*/
  218. /*                     Do Edit Menu                     */
  219. /*______________________________________________________*/
  220.         case editID:
  221.             switch (theItem) {
  222.                 default:
  223.                     break;
  224.                 }
  225.             break;
  226.         default:
  227.             break;
  228.         }
  229.     HiliteMenu(0);
  230.     return;
  231. }
  232.  
  233. /*______________________________________________________*/
  234. /*               Initialization traps                   */
  235. /*______________________________________________________*/
  236. void init()
  237. {
  238.     UnloadSeg(_DataInit);
  239.     InitGraf(&qd.thePort);
  240.     FlushEvents(everyEvent, 0);
  241.     InitWindows();
  242.     InitDialogs(nil);
  243.     InitCursor();
  244.     MaxApplZone();
  245. /*______________________________________________________*/
  246. /*            If not right Machine then stop            */
  247. /*______________________________________________________*/
  248.     OSys = SysEnvirons(VERSION,&theWorld);
  249.     if(!theWorld.hasColorQD)
  250.         Color = TRUE;
  251.     else
  252.         Color = FALSE;
  253.         
  254.     if(theWorld.processor >= env68020)
  255.         CPU20 = TRUE;
  256.     else
  257.         CPU20 = FALSE;
  258.         
  259.     if(!theWorld.hasFPU)
  260.         FPU = TRUE;
  261.     else
  262.         FPU = FALSE;
  263.         
  264.     if(theWorld.systemVersion < 0x0600)
  265.         Sys6 = FALSE;
  266.     else
  267.         Sys6 = TRUE;
  268.                     
  269. /*______________________________________________________*/
  270. /*                    Set menus                         */
  271. /*______________________________________________________*/
  272.     mymenu0 = GetMenu(appleID);
  273.     AddResMenu(mymenu0, 'DRVR');
  274.     InsertMenu(mymenu0,0);
  275.     mymenu1 = newmenu(129,"File");
  276.     appendmenu(mymenu1,"Start;-;Print;-;Quit");
  277.     InsertMenu(mymenu1,0);
  278.     mymenu2 = newmenu(130,"Edit");
  279.     InsertMenu(mymenu2,0);
  280.     DrawMenuBar();
  281.  
  282. /*______________________________________________________*/
  283. /*                  Init variables                      */
  284. /*______________________________________________________*/
  285.     DoneFlag = FALSE;
  286.     yieldTime = 0;
  287.     return;
  288. }
  289.  
  290. main()
  291. {
  292.     Boolean        track;
  293.     long        growResult;
  294. /*______________________________________________________*/
  295. /*                   Main Event loop                    */
  296. /*______________________________________________________*/
  297.     init();
  298.     for ( ;; ) {
  299.         if (DoneFlag) {
  300.             ExitToShell();
  301.             }
  302.         if (WaitNextEvent(everyEvent, &myEvent, yieldTime, nil)) {
  303.             switch (myEvent.what) {
  304.                 case mouseDown:
  305.                     switch (FindWindow(myEvent.where, &whichWindow)) {
  306.                         case inSysWindow:
  307.                             SystemClick(&myEvent, whichWindow);
  308.                             break;
  309.                         case inMenuBar:
  310.                             doCommand(MenuSelect(myEvent.where));
  311.                             break;
  312.                         case inContent:
  313.                             break;
  314.                         case inDrag:
  315.                             DragWindow (whichWindow, myEvent.where, &TotalRect);
  316.                             EraseRect (&whichWindow->portRect);
  317.                             DrawGrowIcon (whichWindow);
  318.                             break;
  319.                         case inGrow:
  320.                             growResult = GrowWindow (whichWindow, myEvent.where,
  321.                                                     &minRect);
  322.                             SizeWindow(whichWindow, LoWord(growResult), 
  323.                                     HiWord(growResult), TRUE);
  324.                             EraseRect (&whichWindow->portRect);
  325.                             DrawGrowIcon (whichWindow);
  326.                             break;
  327.                         case inGoAway:
  328.                             track = TrackGoAway (whichWindow, myEvent.where);
  329.                             if (track)
  330.                                 CloseWindow (whichWindow);
  331.                             break;
  332.                         case inZoomIn:
  333.                             track = TrackBox (whichWindow, myEvent.where, inZoomIn);
  334.                             if (track) {
  335.                                 ZoomWindow (whichWindow, inZoomIn, TRUE);
  336.                                 EraseRect (&whichWindow->portRect);
  337.                                 DrawGrowIcon (whichWindow);
  338.                                 }
  339.                             break;
  340.                         case inZoomOut:
  341.                             track = TrackBox (whichWindow, myEvent.where, inZoomOut);
  342.                             if (track) {
  343.                                 ZoomWindow (whichWindow, inZoomOut, TRUE);
  344.                                 EraseRect (&whichWindow->portRect);
  345.                                 DrawGrowIcon (whichWindow);
  346.                                 }
  347.                             break;
  348.                         default:
  349.                             break;
  350.                         }
  351.                     break;
  352.                 case keyDown:
  353.                     break;
  354.                 case autoKey:
  355.                     break;
  356.                 case updateEvt:
  357.                     if ((WindowPtr) myEvent.message == myWindow) {
  358.                         BeginUpdate((WindowPtr) myWindow);
  359.                         EndUpdate((WindowPtr) myWindow);
  360.                         }
  361.                     break;
  362.                 case diskEvt:
  363.                     break;
  364.                 case activateEvt:
  365.                     break;
  366.                 case app4Evt:
  367.                     if ((myEvent.message << 31) == 0) { /* Suspend */
  368.                         yieldTime = 30;
  369.                         HideWindow((WindowPtr) myWindow);
  370.                         }
  371.                     else { /* Resume */
  372.                         yieldTime = 0;
  373.                         ShowWindow((WindowPtr) myWindow);
  374.                         SetPort((WindowPtr) myWindow);
  375.                         }
  376.                     break;
  377.                 default:
  378.                     break;
  379.                 }
  380.             }
  381.         }
  382. }